#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    printf("stdin->fd %d\n", stdin->_fileno);
    printf("stdout->fd %d\n", stdout->_fileno);
    printf("stderr->fd %d\n", stderr->_fileno);
    int fd = open("mylog.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    /*
    int fd1 = open("mylog1.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    int fd2 = open("mylog2.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    int fd3 = open("mylog3.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    int fd4 = open("mylog4.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    */ 
    
    if(fd < 0)
    {
        printf("open file error\n");
        return 1;
    }
    
    const char* message = "666666666\n";
    write(fd, message, strlen(message));
    /*
     * 0 stdin
     * 1 stdout
     * 2 stderr
     *
    printf("fd %d\n", fd);
    printf("fd1 %d\n", fd1);
    printf("fd2 %d\n", fd2);
    printf("fd3 %d\n", fd3);
    printf("fd4 %d\n", fd4);
    */
    close(fd);
    return 0;
}

/*
#define ONE 1
#define TWO 2
#define THREE 4
#define FOUR 8

void show(int flags)
{
    if(flags & ONE)
    {
        printf("function111\n");
    }
    if(flags & TWO)
    {
        printf("function222\n");
    }
    if(flags & THREE)
    {
        printf("function333\n");
    }
    if(flags & FOUR)
    {
        printf("function444\n");
    }
    
}


int main()
{
    show(ONE);
    printf("-------------------\n");
    show(ONE | TWO);
    printf("-------------------\n");
    show(ONE | TWO | THREE);
    printf("-------------------\n");
    show(ONE | TWO | THREE | FOUR);
    printf("-------------------\n");
    return 0;
}
*/ 

/*
int main()
{
    printf("pid %d\n", getpid());
    FILE* fp = fopen("log.txt", "w");
    if(fp == NULL)
    {
        perror("fp\n");
        return 0;
    }
    
    const char* message = "hello fd";

    fwrite(message, 1, strlen(message), fp);

    fclose(fp);
    sleep(1000); 

    return 0;
}
*/ 
